// import * as PIXI from 'pixi.js'
// import Card, { updatedCardSets } from '@renderer/views/Card'
import { defineStore } from 'pinia'
const useCardsStore = defineStore('cards', {
  state: () => ({
    cards: [] as Wx.Card.Data[],
    diys: [] as Wx.Card.Data[],
    diyDataMap: new Map<number, Wx.Card.Data>(), // DIY卡牌ID与数据的映射
    filterCards: [] as Wx.Card.Data[],
    current: 1, // 当前页
    fontSize: 32, // 字体大小
    from: 'diys' as 'cards' | 'diys', // 来源: cards | diys // TODO
  }),
  getters: {
    getCards(state): Wx.Card.Data[] {
      return state.cards
    },
    getDiys(state): Wx.Card.Data[] {
      return state.diys
    },
    // 获取当前展示类型的卡牌数据数组
    getFrom(state): Wx.Card.Data[] {
      if (state.from === 'diys') {
        return state.diys
      } else {
        return state.cards
      }
    },
    // 总页数
    total: (state) => {
      let len = 0
      if (state.from === 'diys') {
        len = useCardsStore().getDiys.length
      } else {
        len = useCardsStore().getCards.length
      }
      return Math.ceil(len / 8) || 1
    },
  },
  actions: {
    setCards(cards: Wx.Card.Data[]) {
      this.cards = cards
      this.setFilterCards(cards)
    },
    setDiysData(map: Map<number, Wx.Card.Data>) {
      this.diyDataMap = map
    },
    setDiys(diys: Wx.Card.Data[]) {
      this.diys = diys
    },
    setFilterCards(cards: Wx.Card.Data[]) {
      this.filterCards = cards
    },
    setCurrent(num: number) {
      if (num < 1) {
        this.current = 1
      } else if (num > this.total) {
        this.current = this.total
      } else {
        this.current = num
      }
    },
    add() {
      if (this.current < this.total) {
        this.current++
      }
    },
    subtract() {
      if (this.current > 1) {
        this.current--
      }
    },
    clear() {
      this.current = 1
    },
    changeFrom() {
      if (this.from === 'cards') {
        this.from = 'diys'
      } else {
        this.from = 'cards'
      }
    },
  },
})

export default useCardsStore
